package com.blog.config;

import com.blog.interceptor.DataInterceptor;
import com.blog.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 任浩
 * @version 1.0
 */

@EnableWebMvc //表示启用Spring MVC拦截器
@Configuration
public class GlobalInterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Autowired
    private DataInterceptor dataInterceptor;

    /**
     * 具体实现拦截器的方法。
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        /**
         * addPathPatterns 是添加需要拦截的路径
         * excludePathPatterns 配置不需要拦截的路径
         */

        registry.addInterceptor(loginInterceptor).addPathPatterns("/**").excludePathPatterns("/user/login");
        registry.addInterceptor(dataInterceptor).addPathPatterns("/**");
    }
}
